//
//  AppDelegate.m
//  A段项目,漫画
//
//  Created by dllo on 15/4/20.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "AppDelegate.h"
#import "UMSocial.h"

@interface AppDelegate ()
@property(nonatomic, assign)BOOL isFirstStart;
@end

@implementation AppDelegate

-(instancetype)init{
    self = [super init];
    if (self) {
        [self isFirstStartForCartoon];
        [MidTools shareMidTools].delegate3 = self;
    }
    return self;
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    
//    　　设置屏幕亮度
//    [[UIScreen mainScreen] setBrightness:mslider];
    
    if (self.isFirstStart) {
        NSLog(@"第一次启动");
        beginAnimationViewController *beginVC = [[beginAnimationViewController alloc] init];
        UINavigationController *beginNA = [[UINavigationController alloc] initWithRootViewController:beginVC];
        beginVC.navigationController.navigationBarHidden = YES;
        self.window.rootViewController = beginNA;
        [beginVC release];
        //在沙盒创建标志文件
        
    }else{
        NSLog(@"不是第一次启动");
        RootViewController *rootVC = [[RootViewController alloc] init];
        self.window.rootViewController = rootVC;
        [rootVC release];
    }
    [self.window makeKeyAndVisible];
    [self working];
    
    
    [UMSocialData setAppKey:@"55406a3ce0f55a7bd5002d90"];
    
    return YES;
}

- (void)working{
    AFNetworkReachabilityManager *mgr = [AFNetworkReachabilityManager sharedManager];
    
    // 2.设置网络状态改变后的处理
    [mgr setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        // 当网络状态改变了, 就会调用这个block
        switch (status) {
            case AFNetworkReachabilityStatusUnknown: // 未知网络
                NSLog(@"未知网络");
                
                break;
                
            case AFNetworkReachabilityStatusNotReachable: // 没有网络(断网)
                NSLog(@"没有网络(断网)");
                
                break;
            case AFNetworkReachabilityStatusReachableViaWWAN: // 手机自带网络
                NSLog(@"手机自带网络");
                
                break;
            case AFNetworkReachabilityStatusReachableViaWiFi: // WIFI
                NSLog(@"WIFI");
                
                break;
        }
    }];
    
    // 3.开始监控
    [mgr startMonitoring];
}
- (void)modexChangeByNow:(BOOL)isNight{
    if (isNight) {
        self.window.alpha = 1;
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"日间模式切换成功" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
        [alert show];
        [alert release];
    }else{
        self.window.alpha = 0.3;
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"夜间模式切换成功" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
        [alert show];
        [alert release];
    }
}
- (void)isFirstStartForCartoon{
    NSFileManager *manager = [NSFileManager defaultManager];
    //获取沙盒路径
    NSArray *sandBox = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *sandBoxPath = [sandBox lastObject];
    //拼接文件路径
    NSString *filePath = [sandBoxPath stringByAppendingPathComponent:@"第一次运行"];
    if (![manager fileExistsAtPath:filePath]) {
        self.isFirstStart = YES;
        //第一次启动之后创建文件
        NSLog(@"%@",filePath);
        [manager createDirectoryAtPath:filePath withIntermediateDirectories:YES attributes:nil error:nil];
    }else{
        NSLog(@"%@",filePath);
        self.isFirstStart = NO;
    }
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
